var account = {};

account.isodos = function(forma) {
	if (!account.checks(forma)) {
		return false;
	}

	var req = newRequest();
	if (notSet(req)) {
		return false;
	}

	req.onreadystatechange = function() {
		account.isodosCheck(req);
	};
	openRequest(req, 'account/isodos');

	var params = 'login=' + forma.login.value.uri();
	params += '&kodikos=' + forma.kodikos.value.uri();

	req.send(params);
	return false;
}

account.isodosCheck = function(req) {
	if (req.readyState != 4) {
		return;
	}
	if (req.status != 200) {
		fyi('Access denied!');
		return;
	}	
	if (!req.responseText.match(/@ok@$/)) {
		fyi(req.responseText);
		return;
	}

	window.location = globals.server + 'index.php';
}

account.checks = function(forma) {
	forma.login.value = forma.login.value.trim();	

	var errfld = null;

	if (forma.kodikos.value === '') {
		globals.misc.setInputColor(forma.kodikos, globals.colors.error);
		errfld = forma.kodikos;
	}

	if (!forma.login.value.validLogin()) {
		globals.misc.setInputColor(forma.login, globals.colors.error);
		errfld = forma.login;
	}

	if (isSet(errfld)) {
		errfld.focus();
		return false;
	}

	return true;
}
